package com.example.api.config;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.cloud.loadbalancer.cache.LoadBalancerCacheManager;
import org.springframework.context.annotation.Bean;

import java.util.Collections;
import java.util.concurrent.TimeUnit;

//@Configuration
public class LoadBalancerConfig {
    @Bean
    public LoadBalancerCacheManager cacheManager() {
        SimpleCacheManager cacheManager = new SimpleCacheManager();
        cacheManager.setCaches(Collections.singletonList(new CaffeineCache("default",
                Caffeine.newBuilder()
                        .expireAfterWrite(10, TimeUnit.SECONDS)
                        .maximumSize(1000)
                        .build())));
        return (LoadBalancerCacheManager) cacheManager;
    }
}
